package com.file.controller;

import com.file.config.MyWebConfig;
import com.file.msg.RequestData;
import com.file.msg.RequestMsg;
import com.file.sys.SysMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

import java.io.File;
@RestController
@Slf4j
@RequestMapping("/sys")
public class SysController {
    @PostMapping("/path")
    public RequestData setPath(String p){
        log.info("p:"+p);
        if (null != p && !"".equals(p)){
            File f = new File(p);
            log.info(f.exists()+"");
            if (f.exists()){
                SysMsg.path.set(p);
            }
            else
                return new RequestData(RequestMsg.ERROR_NOT_EXSIST_DIR,null);
        }
        return new RequestData(RequestMsg.SYS_ALTER_ROOT_SUCCESS,"当前path:"+p);
    }
}
